﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CSharp.Libs.PathSyncer;
using System.Diagnostics;
using System.Threading;

namespace CSharp.Libs.PathSyncer.Debugging
{
    class Program
    {
        #region declarations
        private static Stopwatch sw = new Stopwatch();

        #region file object debugging
        private static FileObject fo = new FileObject()
        {
            Path = @"d:\OpenDesign",
            FileName = @"OpenDesign WSTRechner.7z",
        };
        private static FileHashCalculator fOps = new FileHashCalculator();
        #endregion

        #region sync path debugging
        private static SyncPath sp = new SyncPath()
        {
            Path = @"D:\COMOS",
        };
        private static PathScanner scanner = new PathScanner();
        #endregion
        #endregion



        #region main program
        static void Main(string[] args)
        {
            

            Console.SetCursorPosition(0, 10);
            Console.WriteLine("Event output:");
            
            sw.Start();

            /*Test HashCalculator*/
            //fOps.FileHashCalculated += fOps_FileHashCalculated;
            //fOps.HashFileObject = fo;
            //fOps.CalculateFileHashAsync();

            /*Test PathScanner*/
            scanner.PathScannerProgress += scanner_PathScannerProgress;
            scanner.SyncPathObject = sp;
            scanner.ScanPathAsync();
            
            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Main() output:");
            Console.WriteLine("Elapsed: " + sw.Elapsed.ToString());

            Console.SetCursorPosition(0, 23);
            Console.WriteLine("--------------------------------------------------------");
            Console.Write("Press any key to exit");
            Console.ReadKey();
        }
        #endregion



        #region event handling
        static void scanner_PathScannerProgress(object sender, PathScannerProgressEventArgs e)
        {
            int intOldTop = Console.CursorTop;
            int intOldLeft = Console.CursorLeft;
            Console.SetCursorPosition(0, 11);
            Console.WriteLine("Started...");
            Console.WriteLine("FileCount: " + e.FileCount);
            Console.WriteLine("FileIndex: " + e.CurrentFileIndex);
            Console.WriteLine("FileName : " + e.CurrentFileName);
            if (e.ProgressType == PathScannerProgressType.Finished)
            {
                sw.Stop();
                Console.WriteLine("Finished. Took " + sw.Elapsed + "                                    ");
            }
            Console.SetCursorPosition(intOldLeft, intOldTop);
        }

        static void fOps_FileHashCalculated(object sender, FileHashCalculatedEventArgs e)
        {
            int intOldTop = Console.CursorTop;
            int intOldLeft = Console.CursorLeft;
            Console.SetCursorPosition(0, 11);
            Console.WriteLine("Calculated Hash via EventArgs: " + e.CalculatedHash);
            Console.WriteLine("Calculated Hash via global FileObject: " + fo.Hash);
            sw.Stop();
            Console.WriteLine("Finished. Took " + sw.Elapsed + "                                    ");
            Console.SetCursorPosition(intOldLeft, intOldTop);
        }
        #endregion
    }
}
